package algo.math.evaluator.context.functions;

import algo.math.evaluator.base.exceptions.UnrecognizedToken;
import algo.math.evaluator.value.IValue;
import algo.math.evaluator.value.Value;


/**
 * Absolute value function
 */
public class Abs extends Function {
	
	public Abs()
	{
		super._name = "abs";
		super._argsNb = 1;
	}

	/* (non-Javadoc)
	 * @see algo.math.evaluator.context.functions.Function#resolve(algo.math.evaluator.value.IValue[])
	 */
	@Override
	public IValue resolve(IValue[] args) {
		
		if (args.length == super._argsNb)
		{
		
		if (args.length >0)
		{
			IValue v = new Value();
			try {
				v.setValue(args[0].getIntegerValue()+'.'+args[0].getDecimalValue(), args[0].getBase());
				return v;
			} catch (UnrecognizedToken e) {
				e.printStackTrace();
			}
		
		}
		return null;
		
		}
		return null;
	}
}
